<template>
	<cl-dialog
		title="选择日期"
		:visible.sync="visible"
		width="30%"
		append-to-body
		@close="reset"
	>
		<el-form
			:model="form"
			:rules="rules"
			ref="form"
			label-width="100px"
			label-position="top"
			class="demo-form"
		>
            <el-form-item label="日期" prop="pay_date">
                <cl-date-picker
                    v-model="form.date"
                    placeholder="选择日期"
                    style="width: 100%"
                    value-format="yyyy-MM-dd"
                    :picker-options="pickerOptions"
                />
            </el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="close">关闭</el-button>
			<el-button type="primary" :loading="saving" @click="submit">确定</el-button>
		</template>
	</cl-dialog>
</template>

<script>

import dayjs from "dayjs";

export default {
	components: {

	},
	data() {
		return {
			saving: false,
			visible: false,
			type: "",
			form: {
				date: '',
                end_date: '',
                account_id: 0, //id
			},
			rules: {
				biz_id: [{ required: true, message: "请选择所属事业部" }],
				name: [{ required: true, message: "请填写名称" }],
                email: [{ required: true, message: "请填写登录邮箱" }],
			},
            pickerOptions: {
				disabledDate(time) {
					let now = dayjs();
					let date = dayjs(time);
					return date.isAfter(now);
				}
			},
		};
	},
	computed: {
	},
	created() {
		this.form.biz_id = this.getCurrBiz();
	},
	methods: {
		open(row) {
            this.form.account_id = row.id
			this.visible = true
		},
		submit() {
			this.$refs.form.validate(async (valid, errors) => {
				this.showFormErr(errors);
				if (!valid) return;
				this.saving = true;
				const { account_id, date } = this.form;
                const param = {
                    account_id,
                    start_date: date,
                    end_date: date
                }
				await this.$service.oceanengine.getReport(param).done(() => {
					this.saving = false;
				});
				// this.$refs.drawer.AddAccounts();
				this.$message.success(
					`获取成功`
				);
				this.close();
			});
		},
		reset() {
			this.saving = false;
			this.$refs.form.resetFields();
			this.resetForm();
		},
		close() {
			this.reset();
			this.visible = false
		},
		//切换事业部
		changeBiz() {
			this.init();
		},
		resetForm() {
			this.$resetFields(this.form);
			this.form.biz_id = this.getCurrBiz();
			this.form.id = undefined;
		}
	}
};
</script>

<style></style>
